<?php

namespace App\Console;

use App\Models\Filter;
use App\Models\Order;
use App\Models\SharpToGoods;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        //
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        // $schedule->command('inspire')
        //          ->hourly();
	    // 每天凌晨2点统计一次
	    $schedule->call(function () {
	    	$filter = new Filter();
	    	$filter->createFilter();
	    })->dailyAt('2:00')->name('定时统计');
	    
	    // 定时任务检查结束的秒杀活动，返回剩余库存
        $schedule->call(function () {
         	SharpToGoods::scheduleReturnAllStock();
         })->everyMinute()->name('返回秒杀活动剩余库存');
        
        // 定时任务检查超时未支付订单
        $schedule->call(function () {
            Order::cancelOverTimeOrder();
        })->everyMinute()->name('检查超时未支付订单');
        
		// *           *        *        *        *           command
		// minute     hour     day     month     week         command
		// 分          时       天       月       星期          命令
	    // 0-59/2   *  *  *  * /data/wwwroot/default/ktv_lara_admin php artisan schedule:run
        // 0 0 * * * /usr/bin/curl http://www.xxx.com 每天凌晨
        // 0 2 * * * /usr/bin/curl http://www.xxx.com
        // */1 * * * * /usr/bin/curl http://www.xxx.com  设置每分钟执行一次test.php文件 Esc->:wq退出保存 (*/1 * * * *也代表每一分钟执行)
	    //* * * * * /usr/bin/curl https://dev-ktvnewproapi.ffun360.com/auto-cancel
    }

    /**
     * Register the commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        $this->load(__DIR__.'/Commands');

        require base_path('routes/console.php');
    }
}
